package com.ln.lnzw.adapter;

import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.blankj.utilcode.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ln.lnzw.R;
import com.ln.lnzw.bean.ServerSubscribeRecomBean;

import java.util.List;

/**
 * 作者 : wlt
 * 创建时间:  2018-04-25
 * QQ : 1346947404
 * 邮箱:wanglt_android@163.com
 * 类说明:
 * In me the tiger sniffs the rose
 */

public class ServerSubscribeTopAdapter extends BaseQuickAdapter<ServerSubscribeRecomBean,BaseViewHolder> {
    /**
     * 提出这些主要是为了进行适配
     */
    /**
     * 服务的总布局
     */
    private RelativeLayout rl_recom_content;
    /**
     * 服务icon
     */
    private ImageView iv_recom_icon;
    /**
     * 是否订阅
     */
    private ImageView iv_recom_subscribe;

    public ServerSubscribeTopAdapter(int layoutResId, @Nullable List<ServerSubscribeRecomBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ServerSubscribeRecomBean item) {

        rl_recom_content = helper.getView(R.id.rl_recom_content);

        ViewGroup.LayoutParams layoutParams1 = rl_recom_content.getLayoutParams();
        layoutParams1.height = ScreenUtils.getScreenWidth()*19/110;
        rl_recom_content.setLayoutParams(layoutParams1);

        iv_recom_icon = helper.getView(R.id.iv_recom_icon);

        ViewGroup.LayoutParams layoutParams2 = iv_recom_icon.getLayoutParams();
        layoutParams2.width = ScreenUtils.getScreenWidth()*8/75;
        layoutParams2.height = ScreenUtils.getScreenWidth()*8/75;
        iv_recom_icon.setLayoutParams(layoutParams2);

        iv_recom_subscribe = helper.getView(R.id.iv_recom_subscribe);

        ViewGroup.LayoutParams layoutParams3 = iv_recom_subscribe.getLayoutParams();
        layoutParams3.width = ScreenUtils.getScreenWidth()*17/110;
        layoutParams3.height = ScreenUtils.getScreenWidth()*9/110;
        iv_recom_subscribe.setLayoutParams(layoutParams3);

        helper.setText(R.id.tv_recom_appname,item.getAppName())
              .setText(R.id.tv_recom_applocation,item.getLocation());
        if (item.getRecommend().equals("1")){
            iv_recom_subscribe.setImageResource(R.mipmap.fuwu_subscribedetails_yiding);
        }else {
            iv_recom_subscribe.setImageResource(R.mipmap.fuwu_subscribedetails_dingyue);
        }
        Glide.with(mContext).load(item.getSubscriberIcon()).placeholder(R.mipmap.icon_fwzwt02).error(R.mipmap.icon_fwzwt02).into(iv_recom_icon);
        helper.addOnClickListener(R.id.iv_recom_subscribe);
    }
}
